<template>
  <div class="saech_filer_box">
    <el-form
      :model="searchForm"
      ref="form"
      label-position="top"
      label-width="auto"
      :inline="false"
      size="small"
    >
      <el-row :gutter="20">
        <el-col :span="24" :offset="0">筛选</el-col>
        <el-col :span="24" :offset="0">
          <el-form-item label="名称" prop="name">
            <el-input
              v-model="searchForm.name"
              placeholder="请输入"
            ></el-input> </el-form-item
        ></el-col>
        <el-col :span="24" :offset="0">
          <el-form-item label="版本" prop="version">
            <el-input
              v-model="searchForm.version"
              placeholder="请输入"
            ></el-input> </el-form-item
        ></el-col>
        <!-- <el-col :span="24" :offset="0">
          <el-form-item label="创建时间">
            <el-date-picker
              class="w100"
              v-model="searchForm.value1"
              type="datetime"
              placeholder="选择日期时间"
            >
            </el-date-picker> </el-form-item
        ></el-col> -->
        <el-col :span="24" :offset="0">
          <el-form-item label="创建人" prop="author">
            <el-select
              v-model="searchForm.author"
              value-key=""
              placeholder="请选择"
              clearable
              filterable
              class="w100"
            >
              <el-option
                v-for="item in userList"
                :key="item.username"
                :label="item.username"
                :value="item.username"
              >
              </el-option>
            </el-select> </el-form-item
        ></el-col>
        <el-col :span="24" :offset="0">
          <el-form-item label="状态" prop="state">
            <el-radio-group v-model="searchForm.state">
              <el-radio :label="'false'">关闭</el-radio>
              <el-radio :label="'true'">开启</el-radio>
            </el-radio-group></el-form-item
          ></el-col
        >
      </el-row>
    </el-form>
    <div class="search_btns flex-x flex-space">
      <el-button style="width: 49%" class="reset" size="mini" @click="reSet"
        >重置</el-button
      >
      <el-button
        style="width: 49%"
        class="submit"
        size="mini"
        @click="submitForm"
        type="primary"
        >提交</el-button
      >
    </div>
  </div>
</template>

<script>
import { getTemplate } from "@/api/technology";
import _ from "lodash";
export default {
  props: {
    userList: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      searchForm: {
        author: "",
        name: "",
        state: "",
        version: "",
      },
    };
  },
  mounted() {
    this.getTemplate();
  },
  methods: {
    getTemplate() {
      getTemplate({
        page: 1,
        pageSize: 0,
      })
        .then((r) => {
          const { data } = r;

          this.tableData = _.uniqBy(data.results, "author");
        })
        .finally((f) => {});
    },

    //重置
    reSet() {
      this.searchForm = {
        author: "",
        name: "",
        state: "",
        version: "",
      };
      this.$emit("setFilterList");
    },
    submitForm() {
      if (
        this.searchForm.version ||
        this.searchForm.author ||
        this.searchForm.name ||
        this.searchForm.state
      ) {
        this.$emit("setFilterList", this.searchForm);
      } else {
        this.$emit("setFilterList");
      }
    },
  },
};
</script>

<style lang='scss' scoped>
.saech_filer_box {
  position: relative;
  height: 100%;
  /deep/.el-form-item {
    margin-bottom: 10px;
    .el-form-item__label {
      padding-bottom: 0 !important;
    }
  }
  .search_btns {
    width: 100%;
    position: absolute;
    bottom: 0;
    padding: 10px;
    left: 0;
  }
}
</style>